package com.atguigu.tingshu.search.listener;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * title:
 * author: zgl
 * date: 2024/3/2
 * description：
 */
@Component
public class SearchListener {
    @Autowired
    private SearchService searchService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upAlbum(String albumId, Acknowledgment ack) {
        if (StringUtils.isBlank(albumId)) {
            ack.acknowledge();
            return;
        }
        searchService.upAlbum(Long.valueOf(albumId));
        ack.acknowledge();
    }


    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lowAlbum(String albumId, Acknowledgment ack) {
        if (StringUtils.isBlank(albumId)) {
            ack.acknowledge();
            return;
        }
        searchService.lowAlbum(albumId);
        ack.acknowledge();
    }
}
